<body class="gr">

<div class="navBar">
	<a class="left" href="wap.php?app=member&act=index"><i class="return"></i></a>
	<div class="titleView-x">我的订单</div>
</div>

<div class="member-order">
	<div class="pullRefresh" status="{if isset($status)}{$status}{else}0{/if}">
		<header>
			<ul class="switchView ge-bottom">
				<li {if !isset($status) || $status==1}class="this"{/if}><a href="wap.php?app=member&act=order&status=1">支付成功</a></li>
				<li {if isset($status) && $status=='-1,-2'}class="this"{/if}><a href="wap.php?app=member&act=order&status=-1,-2">失效订单</a></li>
			</ul>
		</header>

		<ul class="list tableView tableView-noLine">
			{foreach from=$data item=g}
			<li class="ge-bottom">
				<a href="?app=member&act=order_detail&for_pay={$g->differ_money}&id={$g->id}">
					<div class="order-sn">
						<font class="scale10-left">订单号：{$g->order_sn}</font>
						<span class="price">￥{number_format($g->total_price,2,'.','')}</span>
					</div>
					<div class="name">{if is_array($g->months)}{if count($g->months)==1}{$g->months[0]}{else}{$g->months[0]} - {$g->months[count($g->months)-1]}{/if}社保{else}-{/if}</div>
					<span class="time scale11-left">{$g->add_time}</span>
					{if $g->status==0}
					<div class="btn">立即支付</div>
					{elseif $g->status==1}
					<div class="btn">我要续费</div>
					{elseif $g->status==-1}
					<div class="btn">重新下单</div>
					{/if}
				</a>
			</li>
			{foreachelse}
			<div class="norecord">当前没有任何订单</div>
			{/foreach}
		</ul>
	</div>
</div>

<script>
var offset = $('.pullRefresh .list > li').length;
function createHtml(g){
	var html = '<li class="ge-bottom">\
		<a href="?app=member&act=order_detail&for_pay=1&id='+g.id+'">\
			<div class="order-sn">\
				<font class="scale10-left">订单号：'+g.order_sn+'</font>\
				<span class="price">￥'+numberFormat(g.total_price,2)+'</span>\
			</div>\
			<div class="name">'+($.isArray(g.months)?((g.months.length==1?g.months[0]:g.months[0]+' - '+g.months[g.months.length-1])+'社保'):'-')+'</div>\
			<span class="time scale11-left">'+g.add_time+'</span>';
			if(g.status==0)html += '<div class="btn">立即支付</div>';
			if(g.status==1)html += '<div class="btn">我要续费</div>';
			if(g.status==-1)html += '<div class="btn">重新下单</div>';
		html += '</a>\
	</li>';
	offset++;
	return html;
}
$(function(){
    $('.switchView').switchView({ column:'column', index:$('.switchView .this').index() });
	$('.pullRefresh').pullRefresh({
		header : true,
		footer : true,
		footerNoMoreText : '- END -',
		refresh : function(fn){
			var _this = this;
			offset = 0;
			$.getJSON('api.php?app=member&act=order&status='+_this.attr('status'), function(json){
				if(json.error!=0){ $.overloadError(json.msg);return }
				var html = '';
				if($.isArray(json.data))for(var i=0; i<json.data.length; i++)html += createHtml(json.data[i]);
				_this.find('.tableView').html(html);
				fn();
			});
		},
		load : function(fn){
			var _this = this;
			$.getJSON('api.php?app=member&act=order&status='+_this.attr('status'), { offset:offset }, function(json){
				if(json.error!=0){ $.overloadError(json.msg);return }
				var html = '';
				if($.isArray(json.data))for(var i=0; i<json.data.length; i++)html += createHtml(json.data[i]);
				_this.find('.tableView').append(html);
				fn();
			});
		}
	});
});
</script>